//1. 公用样式
require("../../assets/css/index.less");

require("../../assets/fonts/iconfont.css");
let https = require("../../utils/https.js");
let local = require('../../utils/local')
//2. 当前页面样式
require("./course.less");

//3. 公用js
let dom = require("../../utils/dom.js");
//4. 当前页面的js
dom.ready(function () {
    dom.bMenu("run");
    dom.headMenu("course")

    function getCourse() {
        //1.获取数据
        https.get('/api/train/courseList', {}, function (res) {
            console.log(res);
            //判定
            if (res.errno == 0) {
                res.data.forEach(function (v, i) {
                    //判定i表示放在哪里
                    if (i == 0) {//最新课程
                        newCourse.innerHTML = `
            <li>
                <a href="./courseDetails.html?${v.courseId}">
                    <div class="course-bg"><img src="http://47.96.154.185:3701${v.imgurl}"></div>
                    <h2 class="f14">${v.name}</h2>
                    <p>${v.desc}</p>
                </a>
            </li>
                        `
                    } else {//课程
                        courseList.innerHTML += `
            <li class="courses">
                <a href="./courseDetails.html?${v.courseId}">
                    <div>
                        <img src="http://47.96.154.185:3701${v.imgurl}">
                        <h3>${v.name}</h3>
                        <p>${v.desc}</p>
                    </div>
                </a>
            </li>
                        
                        `
                    }
                });

            }
        })
    }

    //调用
    getCourse()
});
